<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
   <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <meta name="description" content="M2M with Arduino and RasperryPi" />
   <meta name="keywords" content="M2M,Arduino,RasperryPi" />
   <meta name="author" content="Benny Saxen" />
   <link rel="stylesheet" type="text/css" href="m2m-arh.css" title="M2M-SP" media="screen,projection" />
   <?php
include("m2mLib.php");

session_start(); 
$id      = $_SESSION['id'];
$hb      = $_SESSION['hb'];
$login   = $_SESSION['login'];

$s_day    = date('d');
$s_month  = date('m');
$s_year   = date('Y');
$s_sec    = date('s');
$s_min    = date('i');
$s_hour   = date('H');

echo("<title>M2M $id SP</title></head>");

echo("
<STYLE type=text/css>
A:link {COLOR: blue;text-decoration:none;}
A:visited {COLOR: blue}
A:hover {COLOR: green}
BODY {COLOR: black} 
</STYLE>
");

//===================================
$action = $_GET['action'];

if($action == 'logout')
  {
    $login    = 'logout';
    $_SESSION['login'] = $login;
  }
if($action == 'unit')
  {
    $id    = $_GET['id'];
  }
if($action == 'hb')
  {
    $hb    = $_GET['hb'];
    setHeartBeat($id,$hb);
  }
  if($action == 'step')
  {
    $steps = $_GET['steps'];
    $dir   = $_GET['dir'];
    if($steps < 20 && $steps > 0)
		stepper($id,$dir,$steps);
  }


$temp = $_POST['login'];
if($temp)
  {
    $login = $temp;
  }


if($login == 'bsa')
{
getStatus($id);
$hb = $g_hb[$id];
$_SESSION['id'] = $id;
$_SESSION['hb'] = $hb;
$_SESSION['login'] = $login;




//===================================================
// HTML
//===================================================
if(!$id)$id = 9999;

echo("<body>");
echo("<h2>M2M $id $hb  $s_year-$s_month-$s_day $s_hour $s_min $s_sec</h2>");
echo("<a href=\"index.php?id=$id\">MAIN</a>");
$filename = 'ctrl-'.$id.'.arh';
if (file_exists($filename)) {
    echo "Execution Pending";
}
echo("<div align=\"center\">");
showPinStatus($id);

echo("<table border=1><tr><th>");
echo("Unit </th><th>$id</th>");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=1111\">1111</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=2222\">2222</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=3333\">3333</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=4444\">4444</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=5555\">5555</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=6666\">6666</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=7777\">7777</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=8888\">8888</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=unit&id=9999\">9999</a></th> ");	
echo("</tr></table>");

echo("<table border=1><tr><th>");
echo("HeartBeat </th><th>$hb</th>");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=1000\">1s</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=2000\">2s</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=10000\">10s</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=100000\">1m</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=120000\">2m</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=hb&hb=1000000\">10m</a></th> ");
echo("</tr></table>");

echo("<table border=1><tr><th>");
echo("Stepper </th>");
echo("<th><a href=\"m2m-sp.php?id=$id&action=step&steps=5&dir=1\">+5</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=step&steps=10&dir=1\">+10</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=step&steps=5&dir=2\">-5</a></th> ");
echo("<th><a href=\"m2m-sp.php?id=$id&action=step&steps=10&dir=2\">-10</a></th> ");
echo("</tr></table>");

echo("<a href=\"m2m-sp.php?id=$id&action=logout\">LOGOUT</a>");
echo("</div>");
}
else
{
echo("
<form method=\"post\" action=\"m2m-sp.php\" >
<input type=\"text\" name=\"login\" size=\"5\" value=\"\">
<input type=\"submit\" value=\"Login\" > 
</form>
");
}


echo("</body></html>"); 
?>
